<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      .container {
        margin: 0 auto;
        width: 500px;
      }
      #txt {
        display: block;
        width: 100%;
        height: 30px;
        border: 1px solid #ccc;
        text-indent: 10px;
      }
      #list {
        margin: 20px;
        line-height: 2;
        color: #333;
      }
    </style>
  </head>

  <body>
    <div class="container">
      <input id="txt" type="text" placeholder="输入今日事项，然后回车" />
      <ol id="list"></ol>
    </div>
    <script>
      // 当输入了一些文字然后按下回车时，将文本框的内容添加到列表中
      var txt = document.getElementById('txt');
      var ol = document.getElementById('list');
      txt.onkeydown = function (e) {
        if (e.key === 'Enter' && txt.value) {
          var li = document.createElement('li');
          li.innerText = txt.value;
          ol.appendChild(li);
          txt.value = '';
        }
      };
    </script>
  </body>
</html>
